<template>
	<view class="content">
		<view class="skill-block">
			<view class="title-block">
				<view class="title">请选择职介组织</view>
			</view>
			<view class="total-block">
				<view class="total">已选择</view>
				<view class="box" v-for="(item,index) in selectedList" :key="item.id">
					<view class="total-item">{{item.name}}</view>
					<view class="iconfont icon-guanbi" @click="deteteItem(index)"></view>
				</view>
			</view>


			<view class="category">
				<view class="first-category-block ">
					<template v-if="list.length>0">
						<view :key="item.id" v-for="(item,index) in list" class="menu-item">
							<view class="top-item">
								<image :src="item.logo?item.logo:imageUrl+'/job_hunting/job_detail/enterprise.jpg'"
									class="company-photo">
								</image>
								<view class="info-item">
									<view class="name">{{item.name}}</view>
									<view class="info-text">
										人力资源&nbsp;·&nbsp;{{item.scaleText||'暂无'}}
									</view>
									<view class="authentication" style="display: flex;flex-direction: row;">
										<view class="icon-item"
											style="display: flex;flex-direction: row; margin-right: 20rpx;align-items: center;">
											<view class="iconfont icon-AK-MN_dunpai_fill"
												style="color: #F9B04A; font-size: 34rpx;font-weight: bold;"></view>
											<view class="info-text">已认证营业执照</view>
										</view>
										<view class="icon-item"
											style="display: flex;flex-direction: row;align-items: center;">
											<view class="iconfont icon-AK-MN_dunpai_fill"
												style="color: #F9B04A; font-size: 34rpx;font-weight: bold;">
											</view>
											<view class="info-text">已认证手机号</view>
										</view>
									</view>
								</view>
							</view>
							<view class="select-item">
								<view class="btn"
									@click="navigate('/page_other/job_hunting/intermediary/detail?id='+item.id)">查看
								</view>
								<view class="btn2" @click="changeMenuSelected(item)" v-if="selectedList.includes(item)">
									已选择
								</view>
								<view class="btn1" @click="changeMenuSelected(item)" v-else>选择</view>
							</view>
						</view>
					</template>
					<view v-else style="text-align: center;margin-top: 30rpx;">暂无数据</view>
				</view>
				<view class="btn-item">
					<view class="btn-save" @click="handleSave">提交</view>
				</view>
			</view>
		</view>
	</view>
	</view>
</template>

<script>
	import {
		validate
	} from '@/util/validate.js'
	import {
		multipleChoiceChange
	} from '@/util/util.js'
	import {
		isMore
	} from '@/util/util.js'
	import {
		getIntermediaryList
	} from '@/api/job_hunting.js'
	export default {
		data() {
			return {
				id: null,
				page: 1,
				limit: 10,
				more: true,
				total: 0,
				list: [],
				welfare: [0],
				selectedList: [],
				index: 0,
				max: 1,

			}
		},
		methods: {
			changeMenuSelected(item) {
				multipleChoiceChange(this.selectedList, item, this.max)
				this.welfare = multipleChoiceChange(this.welfare, item)
			},
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			refresh() {
				this.page = 1
				this.more = true
				this.getList(true);
			},
			getList(refresh = false) {
				getIntermediaryList({
					page: this.page,
					limit: this.limit
				}).then((res) => {
					let list = res.list ?? [];
					this.list = refresh ? list : [...this.list, ...list],
						this.total = res.count
					this.more = isMore(this.page, this.limit, this.total)
				})
			},
			handleSave() {
				let copy = JSON.parse(JSON.stringify(this.selectedList));
				var data = copy;
				if (data.length === 0) {
					this.showToast('请选择！');
				} else {
					uni.$emit('getIntermediary', data);
					uni.navigateBack()
				}
			},
			deteteItem(index) {
				var that = this;
				uni.showModal({
					title: '提示',
					content: '是否删除当前选择',
					success: function(res) {
						if (res.confirm) {
							that.selectedList.splice(index, 1);
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
		},

		onPullDownRefresh() {
			this.refresh();
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.page++;
				this.getList()
			}
		},
		onLoad(e) {
			console.log(e)
			this.id = e.id
			this.getList(true)
		},
	}
</script>

<style lang="scss">
	page {
		background: #FAFAFA;
	}

	.content {
		width: 100%;
		padding: 30rpx;

		.skill-block {
			margin-top: 40rpx;
			border-radius: 20rpx;
			margin-bottom: 30rpx;

			.title-block {
				display: flex;
				flex-direction: row;
				align-items: center;

				.title {
					font-size: 40rpx;
					font-weight: bold;
				}
			}

			.total-block {
				display: flex;
				flex-direction: row;
				margin-top: 40rpx;
				margin-bottom: 30rpx;
				width: 100%;
				align-items: center;

				.box {
					display: flex;
					flex-direction: row;
					flex-wrap: wrap;
					background-color: #E4EFFF;
					margin-left: 40rpx;
					color: #0256FF;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 28rpx;
					border-radius: 10rpx;
					margin-top: 20rpx;
					padding: 10rpx 24rpx;

					.total-item {}

					.iconfont {
						color: #0256FF;
						margin-left: 20rpx;
						font-size: 28rpx;
					}
				}

			}

			.category {
				display: flex;
				flex-direction: column;
				width: 100%;

				.title {
					margin: 20rpx 0;
				}

				.first-category-block {
					display: flex;
					flex-direction: column;

					.menu-item {
						background-color: #fff;
						border-radius: 30rpx;
						padding: 30rpx;
						margin-bottom: 30rpx;

						.top-item {
							border-bottom: 1px solid #F7F6F9;
							display: flex;
							justify-content: space-between;
							padding-bottom: 30rpx;

							.company-photo {
								width: 150rpx;
								height: 150rpx;
								margin-right: 30rpx;
								border-radius: 20rpx;
								background-color: #F7F6F9;
							}

							.info-item {
								width: calc(100% - 180rpx);
								display: flex;
								flex-direction: column;
								justify-content: space-between;

								.name {
									//margin-bottom: 30rpx;
								}

								.info-text {
									color: #999;
									font-size: 26rpx;
								}
							}
						}

						.select-item {
							display: flex;
							justify-content: flex-end;
							margin-top: 30rpx;

							.btn {
								display: flex;
								align-items: center;
								justify-content: center;
								height: 60rpx;
								width: 160rpx;
								border-radius: 40rpx;
								margin-bottom: 20rpx;
								border: 1px solid #0256FF;
								color: #0256FF;
							}

							.btn1 {
								display: flex;
								align-items: center;
								justify-content: center;
								height: 60rpx;
								width: 160rpx;
								border-radius: 40rpx;
								margin-bottom: 20rpx;
								border: 1px solid #0256FF;
								color: #0256FF;
								margin-left: 20rpx;
							}

							.btn2 {
								display: flex;
								align-items: center;
								justify-content: center;
								height: 60rpx;
								width: 160rpx;
								border-radius: 40rpx;
								margin-bottom: 20rpx;
								background-color: #0256FF;
								color: #fff;
								margin-left: 20rpx;
							}
						}
					}
				}

				.text {
					display: flex;
					justify-content: center;
					font-size: 28rpx;
					margin-top: 50rpx;
				}

				.form-item {
					display: flex;
					flex-direction: row;

					.form-ctr {
						width: 400rpx;
						height: 60rpx;
						border: 1rpx solid #999;
						border-radius: 10rpx;
						margin-right: 20rpx;
					}

					.form-btn {
						width: 180rpx;
						height: 60rpx;
						border-radius: 10rpx;
						background-color: #0256FF;
						color: #fff;
						display: flex;
						align-items: center;
						justify-content: center;
					}
				}

				.btn-item {
					display: flex;
					justify-content: center;

					.btn-save {
						display: flex;
						align-items: center;
						justify-content: center;
						margin-top: 140rpx;
						height: 70rpx;
						width: 420rpx;
						border-radius: 40rpx;
						margin-bottom: 20rpx;
						background-color: #0256FF;
						color: #fff;
					}
				}
			}
		}
	}
</style>